package com.cn.web;

import com.cn.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by chenyuncong on 2018/8/30.
 */
@RestController
@RequestMapping("redis")
public class RedisController {
    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("get")
    public Map<Object, Object> get(String key){
        Map<Object, Object> map = redisUtil.hmget(key);
        return map;
    }

    @GetMapping("set")
    public boolean set(String key,Integer val) {
        Map<String,Object> map =new HashMap<>();
        for(int i=0;i<10;i++){
            map.put(key+i,"小明-aaa"+i+val);
        }
        return redisUtil.hmset(key,map);
    }

    @GetMapping("decr")
    public Long decr(){
        return redisUtil.decr("num-test",1);
    }
    @GetMapping("incr")
    public Long incr(){
        return redisUtil.incr("num-test",1);
    }


}
